package com.ihr360.insurance.controller.benefit;

import com.ihr360.insurance.entity.vo.BenefitCompanySettingEntity;
import com.ihr360.insurance.model.dto.benefits.BenefitCompanySetting;
import com.ihr360.insurance.service.BenefitCompanySettingService;
import com.ihr360.maven.plugin.ModuleCodeStore;
import com.ihr360.maven.plugin.annotation.FunctionDefinition;
import com.ihr360.maven.plugin.annotation.ModuleDefinition;
import com.ihr360.shared.advice.response.DisableResponseAdvice;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 公司薪资设置
 *
 * @author tomtao
 */
@RestController
@RequestMapping("/benefitCompanySettings")
@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.BENEFIT_CODE,
        mainModuleName = ModuleCodeStore.Module.BENEFIT_NAME,
        subModuleCode = ModuleCodeStore.Module.Benefit.STANDING_BOOK_CODE,
        subModuleName = ModuleCodeStore.Module.Benefit.STANDING_BOOK_NAME,
        hasExtendsAbstractRestController = true)
public class BenefitCompanySettingController {

    @Autowired
    private BenefitCompanySettingService benefitCompanySettingService;

    @FunctionDefinition(functionName = "查询公司福利台账审批设置", functionCode = ModuleCodeStore.Function.VIEW)
    @GetMapping(value = "/queryBenefitCompanySetting")
    @DisableResponseAdvice
    public BenefitCompanySettingEntity queryBenefitCompanySetting(@RequestParam String companyId) {
        BenefitCompanySetting benefitCompanySetting = benefitCompanySettingService.queryBenefitCompanySetting(companyId);
        if (benefitCompanySetting == null) {
            return null;
        } else {
            BenefitCompanySettingEntity entity = new BenefitCompanySettingEntity();
            BeanUtils.copyProperties(benefitCompanySetting, entity);
            return entity;
        }
    }

    @FunctionDefinition(functionName = "保存公司福利台账审批设置", functionCode = ModuleCodeStore.Function.UPDATE)
    @ApiOperation(value = "/saveBenefitCompanySetting", notes = "保存公司福利台账审批设置")
    @PostMapping(value = "/saveBenefitCompanySetting")
    public void saveBenefitCompanySetting(@RequestParam String companyId, @RequestBody BenefitCompanySettingEntity entity) {
        benefitCompanySettingService.saveBenefitCompanySetting(companyId, entity);
    }

}
